package com.xiaoyu;

import com.xiaoyu.model.Class;
import com.xiaoyu.service.ClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "班级信息接口")
@RestController
//@CrossOrigin(origins = "http://39.101.65.116:8080")
@CrossOrigin(origins = "http://localhost:8080")
public class ClassController {
    @Autowired
    private ClassService classService;

    @ApiOperation("班级信息查询接口")
    @PostMapping("/classInfo")
    public Class classInfo(@RequestBody Class aClass){
        if (aClass.getId()!=null||aClass.getCname()!=null){
            return classService.findOneClass(aClass);
        }
        return null;
    }

    @ApiOperation("班级列表接口")
    @GetMapping("/classList")
    public List<Class> classList(){
        return classService.allClass();
    }

    @ApiOperation("班级添加接口")
    @PutMapping("/class")
    public void addClass(@RequestBody Class aClass){
        if (!aClass.getCname().equals(""))
            classService.addClass(aClass);
    }

    @ApiOperation("班级删除接口")
    @DeleteMapping("/class")
    public void deleteClass(@RequestBody Class aClass){
        if (aClass.getId()!=null)
            classService.deleteClass(aClass);
    }

    @ApiOperation("班级修改接口")
    @PostMapping("/class")
    public void updateClass(@RequestBody Class aClass){
        if(aClass.getId()!=null&&!aClass.getCname().equals(""))
            classService.updateClass(aClass);
    }

    @ApiOperation("整体信息查询接口")
    @GetMapping("/allInfo")
    public List<Class> allInfo(){
        return classService.allInfo();
    }
}
